package com.coffeeloversupportlibrary.coffeelover.contentshow;

import com.coffeeloversupportlibrary.coffeelover.ApiService;
import com.coffeeloversupportlibrary.coffeelover.callback.ModelCallBack;
import com.coffeeloversupportlibrary.coffeelover.contentshow.entity.OriginArticleDetails;
import com.coffeeloversupportlibrary.coffeelover.networktest.entity.Articles;
import com.coffeeloversupportlibrary.core.base.BaseModel;
import com.coffeeloversupportlibrary.core.data.IDataRepository;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @author puyv
 * @createTime 2021/11/22 20:13
 * @projectName CoffeeLoverSupportLibrary
 * @className ArticleDetailsModel.java
 * @description TODO
 */
public class ArticleDetailsModel extends BaseModel {
    public ArticleDetailsModel(IDataRepository dataRepository) {
        super(dataRepository);
    }

    public void getArticleDetails(ModelCallBack<String,String> callBack,String id){
        getRetrofitService(ApiService.class)
                .requestArticleDetails(id)
                .enqueue(new Callback<OriginArticleDetails>() {
                    @Override
                    public void onResponse(Call<OriginArticleDetails> call, Response<OriginArticleDetails> response) {
                           if(response.body().getSuccess()){
                               callBack.onSuccess(response.body().getContent());
                           }else{
                               callBack.Failure(response.body().getMessage());
                           }
                    }

                    @Override
                    public void onFailure(Call<OriginArticleDetails> call, Throwable t) {
                        callBack.Failure(t.getMessage());
                    }
                });
    }
}
